
package demo.issuetracker.controller;

import demo.issuetracker.model.CustomIdentity;
import demo.issuetracker.entity.User;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;


import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import java.util.Map;
import java.util.List;

/**
 * Glue code to bind Create An Account Service with the view framework (Seam). This class contains
 * a default implementation of the action methods. Please avoid reimplmenting the action methods in this class.
 * The purpose of this class is to declare properties which can be bound to the UI.
 * 
  * This page shows the user an account creation form. Login not required.
  *
 * Automatically generated by clickframes
 * 
 * @author Vineet Manohar
 */
public abstract class GeneratedCreateAccountController extends Controller {
    @In("#{userDao}") 
    protected demo.issuetracker.dao.UserDao userDao;

    @In("#{userService}") 
    protected demo.issuetracker.entity.service.UserService userService;





    /** $!User - INPUT */
    protected User user;

    /** 
     * Get User
     *  
     * @return User
     */
    public User getUser() {
       return this.user;
    }

    /**
     * Set User
     *
     * @param user
     */
    public void setUser(User user) {
        this.user = user;
    }


    protected void initUser() {
        // if ${outputList.id} has not been initialized, initialize it now
        if (getUser() == null) {
            setUser(loadUser());
        }
        
     }

    protected User loadUser() {
    return null;
    }

    protected void reloadUser() {
        clearUser();
        loadUser();
    }

    protected void clearUser() {
        setUser(null);
    }
 
    
	@SuppressWarnings("unused")
	private static final Log logger = LogFactory.getLog(GeneratedCreateAccountController.class);

	@In
	protected CustomIdentity identity;

    @Create
    public void init() {


        // initialize all file inputs
 

        // initialize all file inputs
          // all inputs initialized here 
    }




	/**
	 * This method should be called before the page is loaded
	 * 
	 * All the page parameters should be consumed in this method
	 */    
    public String processPageParameters() {


          // if you need to add more code, override this method in the child class

        return null;
    }





	/** Username
	 *
 	 * Username
 	 */
   
	protected String createAccountFormUsername;

  	@org.hibernate.validator.NotNull(message="Please enter a username.")
  	public String getCreateAccountFormUsername() {
	   return this.createAccountFormUsername;
	}

	public void setCreateAccountFormUsername(String createAccountFormUsername) {
		this.createAccountFormUsername = createAccountFormUsername;
	}
	/** Password
	 *
 	 * Password
 	 */
   
	protected String createAccountFormPassword;

  	@org.hibernate.validator.NotNull(message="Please enter a password.")
     	@org.hibernate.validator.Length( min=6,  message="Password must be at least 6 characters.")
 	public String getCreateAccountFormPassword() {
	   return this.createAccountFormPassword;
	}

	public void setCreateAccountFormPassword(String createAccountFormPassword) {
		this.createAccountFormPassword = createAccountFormPassword;
	}
	/** Repeat Password
	 *
 	 * Repeat Password
 	 */
   
	protected String createAccountFormRepeatPassword;

  	@org.hibernate.validator.NotNull(message="Please repeat your password.")
     	public String getCreateAccountFormRepeatPassword() {
	   return this.createAccountFormRepeatPassword;
	}

	public void setCreateAccountFormRepeatPassword(String createAccountFormRepeatPassword) {
		this.createAccountFormRepeatPassword = createAccountFormRepeatPassword;
	}



 
       public void createAccountFormUsernameValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void createAccountFormPasswordValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void createAccountFormRepeatPasswordValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
        boolean valid = StringUtils.equals(getCreateAccountFormPassword(), valueStr);

        if (!valid) {
            FacesMessage message = new FacesMessage();
            message.setDetail("Input does not match Password");
            message.setSummary("Input does not match Password");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new javax.faces.validator.ValidatorException(message);
        }
    }

 

 
    /**
     *  Converts any form inputs bound to entities to entities, stores them in the map ready to 
     *  be passed to the service methods
     */
    protected User getCreateAccountFormUser() {
         // create a new User from input
        User newUser = userDao.newInstance();

        newUser.setUsername(toText(createAccountFormUsername));
        newUser.setPassword(toText(createAccountFormPassword));
        return newUser;
    }

 
   /**
    * Create account
    *
    *     * Automatically generated by clickframes
    */
   public abstract CreateAccountFormCreateAccountOutcome createAccountFormCreateAccount();




    private static final long serialVersionUID = 1L;

     /**
     * different legal outcomes for Create account 
     * 
     * This page shows the user an account creation form. Login not required.
     */
     public enum CreateAccountFormCreateAccountOutcome {
        /** 
         * Account created
         */ 
        accountCreated    
    }
  }// clickframes::version=665408306::clickframes